package com.zhongxi.guoyuan.view.user.gift;

import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Paint;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.application.MyApplication;
import com.zhongxi.guoyuan.base.BaseActivity;
import com.zhongxi.guoyuan.entity.BaseResponse;
import com.zhongxi.guoyuan.entity.user.GiftResult;
import com.zhongxi.guoyuan.url.Url;
import com.zhongxi.guoyuan.utils.CommonTool;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class GiftDetailActivity extends BaseActivity implements View.OnClickListener {

    private GiftResult result;
    private TextView tvName;
    private TextView tvTotalName;
    private TextView tvTime;
    private TextView tvActivityTime;
    private TextView tvDesc;
    private TextView tvPrice;
    private TextView tvActivityPrice;
    private TextView tvGet;
    private TextView tvShare;
    private String type;
    private Map<String, String> map = new HashMap<String, String>();
    private PopupWindow popupWindow;
    private View popupWindow_view;
    private SHARE_MEDIA platform;
    private String price;
    private TextView tvOrign;
    private TextView tvActivity;
    private UMShareAPI mShareAPI;
    private TextView tvOrignPrice;
    private TextView tvProjectName;
    private TextView tvEndTime;
    private TextView tvActivityEndTime;
    private WebView webView;
    private String status;
    private GiftResult.GiftData gift;
    public static final int resultGift = 1000;
    private boolean isSuccessGift = false;
    private boolean isShare;

    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.activity_gift_detail);
        initTitle();
        mShareAPI = UMShareAPI.get(this);
        tvName = (TextView) findViewById(R.id.tvName);
        tvTotalName = (TextView) findViewById(R.id.tvTotalName);
        tvTime = (TextView) findViewById(R.id.tvTime);
        tvEndTime = (TextView) findViewById(R.id.tvEndTime);
        tvActivityTime = (TextView) findViewById(R.id.tvActivityTime);
        tvActivityEndTime = (TextView) findViewById(R.id.tvActivityEndTime);
        tvDesc = (TextView) findViewById(R.id.tvDesc);
        tvPrice = (TextView) findViewById(R.id.tvPrice);
        tvActivityPrice = (TextView) findViewById(R.id.tvActivityPrice);
        tvGet = (TextView) findViewById(R.id.tvGet);
        tvShare = (TextView) findViewById(R.id.tvShare);
        tvActivity = (TextView) findViewById(R.id.tvActivity);
        tvOrign = (TextView) findViewById(R.id.tvOrign);
        tvOrignPrice = (TextView) findViewById(R.id.tvOrignPrice);
        tvProjectName = (TextView) findViewById(R.id.tvProjectName);
        webView = (WebView) findViewById(R.id.wv);
        initWebView();
    }

    @Override
    protected void initData() {
        super.initData();
        type = "activity";
        String sharekey = getIntent().getExtras().getString("sharekey");
        status = getIntent().getExtras().getString("status");
        getServer(Url.GIFT_DETAIL, null, "&shareKey=" + sharekey, false, null, "get");
    }

    private void initWebView() {
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); //取消滚动条白边效果
        webView.getSettings().setDefaultTextEncodingName("UTF-8");
        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webView.getSettings().setBlockNetworkImage(false);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webView.getSettings().setMixedContentMode(webView.getSettings().MIXED_CONTENT_ALWAYS_ALLOW);  //注意安卓5.0以上的权限
        }
    }

    private boolean activityGift = false;
    private int activityGiftName;

    @Override
    protected void processSuccessResult(String response) {
        super.processSuccessResult(response);
        Gson gson = new Gson();
        try {
            if ("activity".equals(type)) {
                result = gson.fromJson(response, GiftResult.class);
                if (null != result.getSafeobj() && !"".equals(result.getSafeobj())) {
                    MyApplication.getInstance().setSpValue(result.getSafeobj());
                }
                setData();
            } else if ("get".equals(type)) {
                BaseResponse result = gson.fromJson(response, BaseResponse.class);
                if (null != result.getSafeobj() && !"".equals(result.getSafeobj())) {
                    MyApplication.getInstance().setSpValue(result.getSafeobj());
                }
                showSuccessDialog();
            } else if ("share".equals(type)) {
                BaseResponse result = gson.fromJson(response, BaseResponse.class);
                if (null != result.getSafeobj() && !"".equals(result.getSafeobj())) {
                    MyApplication.getInstance().setSpValue(result.getSafeobj());
                }
                activityGift = true;
                activityGiftName = 0;
                showActivityGiftSuccessDialog();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 活动价分享领取后的对话框
     */
    private void showActivityGiftSuccessDialog() {
        AlertDialog.Builder adb = new AlertDialog.Builder(this);
        System.out.println("showSuccessDialog");
        final AlertDialog dialog = adb.create();
        View view = dialog.getLayoutInflater().inflate(R.layout.dialog_gift_detail, null);
        TextView tvTitle = (TextView) view.findViewById(R.id.tv_dialog_title);
        TextView tvDetail = (TextView) view.findViewById(R.id.tv_dialog_detail);
        TextView tvSure = (TextView) view.findViewById(R.id.tv_dialog_sure);
        switch (activityGiftName) {
            case 0:
                tvTitle.setText("感谢您的分享");
                tvDetail.setText("你的礼包已成功领取");
                break;
            case 1:
                tvTitle.setText("感谢您的分享");
                tvDetail.setText("您已经领过大礼包了哟！");
                break;
            case 2:
                tvTitle.setText("很遗憾");
                tvDetail.setText("您的该项大礼包过期了");
                break;
            case 3:
                if (null != gift.getCurrencytype() && !"".equals(gift.getCurrencytype())) {
                    if ("1".equals(gift.getCurrencytype())) {
                        tvTitle.setText("领取失败,你的余额是:" + MyApplication.getInstance().getInnerCurrency() + "美币");
                        tvDetail.setText("您的美币不够,请去摇钱树摇够,再分享一次可领取礼包");
                    } else {
                        tvTitle.setText("领取失败,你的余额是:" + MyApplication.getInstance().getInnerCurrency() + "银币");
                        tvDetail.setText("您的银币不够,需要消费获得等额银币后,再分享一次可领取礼包");
                    }
                }
                break;
        }
        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.setView(view);
        dialog.show();
    }

    /**
     * 直接领取礼包成功
     */

    private void showSuccessDialog() {
        AlertDialog.Builder adb = new AlertDialog.Builder(this);
        final AlertDialog dialog = adb.create();
        View view = dialog.getLayoutInflater().inflate(R.layout.dialog_gift_detail, null);
        TextView tvTitle = (TextView) view.findViewById(R.id.tv_dialog_title);
        TextView tvDetail = (TextView) view.findViewById(R.id.tv_dialog_detail);
        TextView tvSure = (TextView) view.findViewById(R.id.tv_dialog_sure);
        switch (status) {
            case "0":
                if (("1".equals(gift.getCurrencytype()) && CommonTool.sub(MyApplication.getInstance().getInnerCurrency(), gift.getCurrencynum())) || ("2".equals(gift.getCurrencytype()) && CommonTool.sub(MyApplication.getInstance().getSilver(), gift.getCurrencynum()))) {  //美币或银币够用
                    tvTitle.setText("恭喜您");
                    tvDetail.setText("你的礼包已成功领取");
                    isSuccessGift = true;
                    //Intent data=new Intent();
                    setResult(resultGift);
                } else {
                    if (null != gift.getCurrencytype() && !"".equals(gift.getCurrencytype())) {
                        if ("1".equals(gift.getCurrencytype())) {
                            tvTitle.setText("领取失败,你的余额是:" + MyApplication.getInstance().getInnerCurrency() + "美币");
                            tvDetail.setText("您的美币不够,请去摇钱树摇够,就可以直接领取礼包");
                        } else {
                            tvTitle.setText("领取失败,你的余额是:" + MyApplication.getInstance().getInnerCurrency() + "银币");
                            tvDetail.setText("您的银币不够,需要消费获得等额银币后,就可以直接领取礼包");
                        }
                    }
                }

                break;
            case "1":
                System.out.println("抱歉,您已参与过该活动");
                tvTitle.setText("抱歉,您已参与过该活动");
                tvDetail.setVisibility(View.GONE);
                break;
            case "2":
                tvTitle.setText("很遗憾");
                tvDetail.setText("您的该项大礼包过期了");
                break;
        }
        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.setView(view);
        dialog.show();
    }


    /**
     * 添加数据
     */
    private void setData() {
        String name = "";
        String type = "";
        if (null != result.getGift() && !"".equals(result.getGift())) {
            gift = result.getGift();
            if (null != gift.getName() && !"".equals(gift.getName())) {
                tvProjectName.setText(gift.getName());
            }
            if (null != gift.getCurrencytype() && !"".equals(gift.getCurrencytype())) {
                if ("1".equals(gift.getCurrencytype())) {
                    type = "美币";
                } else {
                    type = "银币";
                }
            }
            if (null != gift.getCurrencynum() && !"".equals(gift.getCurrencynum())) {
                tvOrign.setText("市场价：" + gift.getCurrencynum() + type);
                tvOrign.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                tvOrignPrice.setText("市场价：" + gift.getCurrencynum() + type);
                tvPrice.setText(gift.getCurrencynum() + type);
            }
            if (null != gift.getDetailsinfo() && !"".equals(gift.getDetailsinfo())) {
                webView.loadDataWithBaseURL(null, getNewContent(gift.getDetailsinfo()), "text/html", "utf-8", null);
            }
        }
        if (null != result.getActivity() && !"".equals(result.getActivity())) {
            GiftResult.GiftActivity activity = result.getActivity();
            if (null != activity.getName() && !"".equals(activity.getName())) {
                name += activity.getName();
                tvName.setText(name);
                tvTitle.setText(name);
            }

            if (null != result.getGift() && !"".equals(result.getGift())) {
                GiftResult.GiftData gift = result.getGift();
                name += "--" + gift.getName();
                tvTotalName.setText(name);
            }
            if (null != activity.getStime() && !"".equals(activity.getStime())) {
                tvTime.setText("活动开始时间：" + activity.getStime());
                tvActivityTime.setText("活动开始时间：" + activity.getStime());
            }
            if (null != activity.getEtime() && !"".equals(activity.getEtime())) {
                tvEndTime.setText("活动结束时间：" + activity.getEtime());
                tvActivityEndTime.setText("活动结束时间：" + activity.getEtime());
            }
            if (null != activity.getSubject() && !"".equals(activity.getSubject())) {
                tvDesc.setText(activity.getSubject());
            }
            if (null != activity.getAprice() && !"".equals(activity.getAprice())) {
                BigDecimal bd = new BigDecimal(activity.getAprice());
                if ("1".equals(result.getGift().getCurrencytype())) {
                    price = bd.multiply(new BigDecimal(10)) + "";
                } else if ("2".equals(result.getGift().getCurrencytype())) {
                    price = activity.getAprice();
                }
                tvActivityPrice.setText(price + type);
                tvActivity.setText("活动价：" + price + type);
            }
        }
//        tvTotalName.setText(name);
    }

    @Override
    protected void ProcessFailResult(String response) {
        super.ProcessFailResult(response);
        Gson gson = new Gson();
        try {
            BaseResponse result = gson.fromJson(response, BaseResponse.class);
            if (null != result.getSafeobj() && !"".equals(result.getSafeobj())) {
                MyApplication.getInstance().setSpValue(result.getSafeobj());
            }
            if (type.equals("share")) {
                if (result.getCode() == 8007) {
                    activityGift = true;
                    activityGiftName = 1;
                    showActivityGiftSuccessDialog();
                }
            }
            if (1001 == result.getCode()) {
//                showShortToast("用户未登陆");
                Toast.makeText(context, "用户未登录", Toast.LENGTH_LONG);
            } else if (8004 == result.getCode()) {
                Toast.makeText(context, "活动有更新，请重新申请", Toast.LENGTH_LONG);
            } else if (8008 == result.getCode()) {
                Toast.makeText(context, "该项目已下架", Toast.LENGTH_LONG);
            } else if (8002 == result.getCode()) {
                Toast.makeText(context, "您已领取过大礼包！", Toast.LENGTH_LONG);
            } else if (8003 == result.getCode()) {
                Toast.makeText(context, "您的美币或银币不足！", Toast.LENGTH_LONG);
            } else if (8001 == result.getCode()) {
                Toast.makeText(context, "大礼包已过期！", Toast.LENGTH_LONG);
            } else if (8005 == result.getCode()) {
                Toast.makeText(context, "大礼包活动参与失败！", Toast.LENGTH_LONG);
            } else if (8007 == result.getCode()) {
                Toast.makeText(context, "用户已参与该活动！", Toast.LENGTH_LONG);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        ivBack.setOnClickListener(this);
        tvShare.setOnClickListener(this);
        tvGet.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvShare:
                isShare = true;
                //分享
                if (null != popupWindow && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                } else {
                    initPopuWindow();
                }
                break;
            case R.id.tvGet:  //直接领取
                isShare = false;
                if (!activityGift && (("1".equals(gift.getCurrencytype()) && CommonTool.sub(MyApplication.getInstance().getInnerCurrency(), price)) ||
                        ("2".equals(gift.getCurrencytype()) && CommonTool.sub(MyApplication.getInstance().getSilver(), price)))) {
                    showDeductShareDialog();
                } else {
                    //分享
                    if (null != popupWindow && popupWindow.isShowing()) {
                        popupWindow.dismiss();
                    } else {
                        initPopuWindow();
                    }
                }


//                if (status.equals("0")) {
//                    if (("1".equals(gift.getCurrencytype()) && CommonTool.sub(MyApplication.getInstance().getInnerCurrency(), gift.getCurrencynum())) ||
//                            ("2".equals(gift.getCurrencytype()) && CommonTool.sub(MyApplication.getInstance().getSilver(), gift.getCurrencynum()))) {  //美币或银币够用
//                        if (!isSuccessGift) {
//                            showDeductCurrencydialog();
//                        } else {
//                            status = "1";
//                            showSuccessDialog();
//                        }
//                    } else {
//                        showSuccessDialog();
//                    }
//                } else {
//                    showSuccessDialog();
//                }
                break;
            case R.id.ivBack:
                finish();
                break;
        }
    }

    /**
     * 钱币足够,是否确认分享购买的对话框
     */
    private void showDeductShareDialog() {
        AlertDialog.Builder adb = new AlertDialog.Builder(this);
        final AlertDialog dialog = adb.create();
        View view = View.inflate(this, R.layout.dialog_gift_deduct_currency, null);
        TextView tvDeductTitle = (TextView) view.findViewById(R.id.tv_dialog_deduct_title);
        TextView tvDeductDetail = (TextView) view.findViewById(R.id.tv_dialog_deduct_detail);
        LinearLayout tvDeductSure = (LinearLayout) view.findViewById(R.id.tv_dialog_deduct_sure);
        // TextView tvDeductCancle = (TextView) view.findViewById(R.id.tv_dialog_deduct_cancle);
        ImageView iv_cancle = (ImageView) view.findViewById(R.id.iv_cancle);
        TextView tvDeductType = (TextView) view.findViewById(R.id.tv_dialog_deduct_Type);
        switch (gift.getCurrencytype()) {
            case "1":
                tvDeductTitle.setText("你的美币足够支付");
                tvDeductDetail.setText(price);
                tvDeductType.setText("美币");
                break;
            case "2":
                tvDeductTitle.setText("你的银币足够支付");
                tvDeductDetail.setText(price);
                tvDeductType.setText("银币");
                break;
        }
        tvDeductSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //分享
                if (null != popupWindow && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                } else {
                    initPopuWindow();
                }
                dialog.dismiss();
            }
        });

        iv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.setView(view);
        dialog.show();
    }

    /**
     * 够付后,弹出的是否确认支付的框
     */
    private void showDeductCurrencydialog() {
        AlertDialog.Builder adb = new AlertDialog.Builder(this);
        final AlertDialog dialog = adb.create();
        View view = View.inflate(this, R.layout.dialog_gift_deduct_currency, null);
        TextView tvDeductTitle = (TextView) view.findViewById(R.id.tv_dialog_deduct_title);
        TextView tvDeductDetail = (TextView) view.findViewById(R.id.tv_dialog_deduct_detail);
        LinearLayout tvDeductSure = (LinearLayout) view.findViewById(R.id.tv_dialog_deduct_sure);
        //TextView tvDeductCancle = (TextView) view.findViewById(R.id.tv_dialog_deduct_cancle);
        ImageView ivCancle = (ImageView) view.findViewById(R.id.iv_cancle);
        TextView tvDeductType = (TextView) view.findViewById(R.id.tv_dialog_deduct_Type);
        switch (gift.getCurrencytype()) {
            case "1":
                tvDeductTitle.setText("你的美币足够支付");
                tvDeductDetail.setText(gift.getCurrencynum());
                tvDeductType.setText("美币");
                break;
            case "2":
                tvDeductTitle.setText("你的银币足够支付");
                tvDeductDetail.setText(gift.getCurrencynum());
                tvDeductType.setText("银币");
                break;
        }
        tvDeductSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getGift();
                dialog.dismiss();
            }
        });

        ivCancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.setView(view);
        dialog.show();
    }

    /**
     * 弹出分享界面
     */
    private void initPopuWindow() {
        popupWindow_view = getLayoutInflater().inflate(R.layout.pop_shared, null, false);
        popupWindow = new PopupWindow(popupWindow_view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0xb0000000));
        popupWindow.setFocusable(true);
        popupWindow.showAtLocation(tvShare, Gravity.BOTTOM, 0, 0);
        TextView tv_cancle = (TextView) popupWindow_view.findViewById(R.id.tv_cancle);
        LinearLayout ll_qq = (LinearLayout) popupWindow_view.findViewById(R.id.ll_qq);
        LinearLayout ll_wechat = (LinearLayout) popupWindow_view.findViewById(R.id.ll_wechat);
//        LinearLayout ll_microblog = (LinearLayout) popupWindow_view.findViewById(R.id.ll_microblog);
        LinearLayout ll_qzone = (LinearLayout) popupWindow_view.findViewById(R.id.ll_qzone);
        LinearLayout ll_friendscircle = (LinearLayout) popupWindow_view.findViewById(R.id.ll_friendscircle);
        View.OnClickListener shareClickListener = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.ll_qq:
                        platform = SHARE_MEDIA.QQ;
                        break;
                    case R.id.ll_wechat:
                        platform = SHARE_MEDIA.WEIXIN;
                        break;
                    case R.id.ll_qzone:
                        platform = SHARE_MEDIA.QZONE;
                        break;
                    case R.id.ll_friendscircle:
                        platform = SHARE_MEDIA.WEIXIN_CIRCLE;
                        break;
                }
                new ShareAction(GiftDetailActivity.this).setPlatform(platform).setCallback(umShareListener).withTitle(result.getGift().getTitle())
                        .withText(result.getActivity().getSubject()).withTargetUrl(Url.BASE_URL + "/activity/giftpacks/index?sharekey=" + result.getShareKey())
                        .share();
                popupWindow.dismiss();
            }
        };
        ll_qq.setOnClickListener(shareClickListener);
        ll_wechat.setOnClickListener(shareClickListener);
        ll_qzone.setOnClickListener(shareClickListener);
        ll_friendscircle.setOnClickListener(shareClickListener);
        tv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

    }

    private UMShareListener umShareListener = new UMShareListener() {

        @Override
        public void onResult(SHARE_MEDIA platform) {
            if (platform.name().equals("WEIXIN_FAVORITE")) {
                showShortToast("收藏成功啦");
            } else {
                showShortToast("分享成功了!!");
            }
            if (!isShare) {
                if (status.equals("2")) {  //过期
                    activityGiftName = 2;
                    showActivityGiftSuccessDialog();   //price
                } else {  //没过期
                    if (!activityGift) {  //没领取
                        if (("1".equals(gift.getCurrencytype()) && CommonTool.sub(MyApplication.getInstance().getInnerCurrency(), price)) || ("2".equals(gift.getCurrencytype()) && CommonTool.sub(MyApplication.getInstance().getSilver(), price))) {  //美币或银币够用
                            getShareGift(price);  //可以领取
                        } else {
                            activityGiftName = 3;
                            showActivityGiftSuccessDialog();
                        }
                    } else {
                        activityGiftName = 1;  //已领取
                        showActivityGiftSuccessDialog();
                    }
                }
            }
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Log.i("base", "fail");
            showShortToast("分享失败啦");
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Log.i("base", "cancel");
            showShortToast("分享取消了");
        }
    };

    /**
     * 领取大礼包
     */
    private void getGift() {
        type = "get";
        map.clear();
        map.put("giftid", result.getGift().getId());
        map.put("currencytype", result.getGift().getCurrencytype());
        map.put("currencynum", result.getGift().getCurrencynum());
        map.put("gtype", result.getGift().getGifttype());
        getServer(Url.RECEIVE_GIFT, map, "", false, null, "post");
    }

    /**
     * 领取活动礼包
     */
    private void getShareGift(String paynum) {
        type = "share";
        map.clear();
        map.put("giftid", result.getGift().getId());
        map.put("currencytype", result.getGift().getCurrencytype());
        map.put("currencynum", result.getGift().getCurrencynum());
        map.put("paynum", paynum);
        map.put("shareKey", result.getShareKey());
        getServer(Url.RECEIVER_GIFT, map, "", false, null, "post");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    private String getNewContent(String htmltext) {

        String html = "<meta name=\"viewport\" content=\"width=device-width\"><div><p>";


        Document doc = Jsoup.parse(htmltext);
        Elements elements = doc.getElementsByTag("img");
        for (Element element : elements) {
            element.attr("width", "100%").attr("height", "auto");
        }

        return doc.toString();
    }

}
